<?php

namespace app\middleware;

use \ltcms\middleware\Middleware_contract;

class CheckLtcmsLogin implements Middleware_contract
{
    /**
     *  处理请求
     */
    public function handle($request, \Closure $next)
    {
        //判断登录请求
        $loginData=ltcmsLoginInfo();
        if (!(isset($loginData["token"]) && $loginData["token"])) {
            if(request()->isAjax()){
                $response=apiResponse(false,lang("admin.pleaseLogin"),app("errorCode")::AUTH_ENTICATION);
                return jsonResponse($response);
            }else{
                $referer=$request->url(true);
                return redirect("/admin/ltcmsLogin?referer={$referer}");
            }
        }
        $response = $next($request);
        return $response;
    }
}


